<!-- Horizontal Form -->
<div class="box box-info">
	<div class="box-header with-border">
		<!--原user_edit页面 -->
		<h3 class="box-title">添加商品类目信息</h3>
		<h5 class="msg"></h5>
	</div>
	<!-- /.box-header -->
	<!-- form start -->
	<form class="form-horizontal">
		<div class="box-body">
			<div class="form-group">
				
				<label for="usernameId" class="col-sm-2 control-label">分类名称名</label>
				<div class="col-sm-10">
				<p id="msg"></p>
					<input type="text" class="form-control" id="usernameId"
						name="username">
				</div>
			</div>
			<div class="form-group" id="pwdDiv">
				<label for="passwordId" class="col-sm-2 control-label">分类描述</label>

				<div class="col-sm-10">
					<input type="text" class="form-control" id="passwordId">
				</div>
			</div>
			<div class="form-group">
				<label for="emailId" class="col-sm-2 control-label">排序</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="emailId">
				</div>
			</div>
			<!-- /.box-body -->
			<div class="box-footer">
				<button type="button" class="btn btn-default btn-cancel">取消</button>
				<button type="button" class="btn btn-info pull-right btn-save">确定添加</button>
				<!-- <a href="../starter.html" target="_blank">测试超链接</a> -->
			</div>
			<!-- /.box-footer -->
		</div>
	</form>
	<!-- <div class="layui-layer layui-layer-page layui-layer-molv layer-anim"
		id="treeLayer" type="page" times="2" showtime="0" contype="object"
		style="z-index: 59891016; width: 300px; height: 450px; top: 100px; left: 500px; display: none">
		<div class="layui-layer-title" style="cursor: move;">选择部门</div>
		<div class="layui-layer-content" style="height: 358px;">
			<div style="padding: 10px;" class="layui-layer-wrap">
				<ul id="zTreeId" class="ztree"></ul>
				动态加载树
			</div>
		</div>
		<span class="layui-layer-setwin"> <a
			class="layui-layer-ico layui-layer-close layui-layer-close1 btn-cancel"></a></span>
		<div class="layui-layer-btn layui-layer-btn-">
			<a class="layui-layer-btn0 btn-confirm">确定</a> <a
				class="layui-layer-btn1 btn-cancel">取消</a>
		</div>
	</div> -->
</div>
<script type="text/javascript"
	src="bower_components/ztree/jquery.ztree.all.min.js"></script>
<script type="text/javascript" src="bower_components/layer/layer.js"></script>
<script type="text/javascript">
	$(document).ready(
			function() {
				//事件注册
				$(".box-footer").on("click", ".btn-cancel", doCancel).on(
						"click", ".btn-save", doSaveOrUpdate);
				//判断category名是否存在
				$("form").on("blur", "#usernameId", isExists);
			});

	function isExists() {
		//var filedName = $(this).prop("name");
		var filedValue = $(this).val();
		if (filedValue) {
			var params = {
				/* "filedName" : filedName, */
				"filedValue" : filedValue
			};
			var url = "category/categoryNameIsExists";
			$.getJSON(url, params, function(result) {
				if (!result) {
					$("#msg").html("类名已存在");
				} else {
					$("#msg").html(" ");
				}
			});
		}
	}

	function doCancel() {
		//$("#mainContentId").removeData("rowData");
		$("#mainContentId").load("category_list");
	}
	function doSaveOrUpdate() {
		/* var rowData = $("#mainContentId").data("rowData"); */
		//1.获取表单数据
		var params = doGetEditFormData();
		//2.发起异步请求
		var insertUrl = "category/insertCategoryObject";
		console.log("params页面数据", params);
		$.post(insertUrl, params, function(result) {
			if (result.status == 1) {
				alert(result.message, "哈哈哈哈哈");
				doCancel();
			} else {
				alert(result.message);
			}
		})
	}
	/*============================================================= */
	function doGetEditFormData() {
		//获取用户输入的数据
		var params = {
			categoryName : $("#usernameId").val(),
			categoryDescription : $("#passwordId").val(),
			sort : $("#emailId").val(),
		}
		return params;
	}
	function doInitFormData() {
		var data = $("#mainContentId").data("rowData");
		if (!data)
			return;
		$("#pwdDiv").remove();
		console.log(data);
		//初始化用户信息 
		$("#usernameId").val(data.user.username);
		$("#deptId").val(data.user.sysDept ? data.user.sysDept.name : '');
		$("#deptId").data("deptId",
				data.user.sysDept ? data.user.sysDept.id : '');
		$("#emailId").val(data.user.email);
		$("#phoneId").val(data.user.mobile);
		//初始化用户角色信息
		var ids = data.roleIds;
		for ( var i in ids) {
			$("#rolesId input[value='" + ids[i] + "']").prop("checked", true);
		}
	}
</script>






